package com.jinzecloud.reportapproval.controller;

import java.io.IOException;
import java.text.ParseException;
import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import cn.hutool.extra.template.TemplateException;
import com.jinzecloud.reportapproval.bean.ProductInfo;
import com.jinzecloud.reportapproval.dto.Param;
import com.jinzecloud.reportapproval.enums.StateEnum;
import com.jinzecloud.reportapproval.service.ProductInfoService;
import com.jinzecloud.reportapproval.utils.PageUtils;
import com.jinzecloud.reportapproval.utils.R;
import com.jinzecloud.reportapproval.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


/**
 * 推广鉴定信息表
 *
 * @author æ­å°
 * @email 1971240051@qq.com
 * @date 2024-09-03 12:10:44
 */
@RestController
@RequestMapping("reportApproval/productinfo")
@Api(tags = "推广鉴定信息表", description = "推广鉴定信息表", value = "推广鉴定信息表")
public class ProductInfoController {
    @Autowired
    private ProductInfoService productInfoService;

    /**
     * 列表
     */
    @RequestMapping(value = "/list",method = RequestMethod.POST)
    @ApiOperation(value = "推广鉴定信息表列表",notes = "推广鉴定信息表列表")
    //@RequiresPermissions("reportApproval:productinfo:list")
    public R list(@RequestBody Param param){
        PageUtils page = productInfoService.queryPage(param);

        return R.ok().put("page", page);
    }

    @RequestMapping(value = "/checklist",method = RequestMethod.POST)
    @ApiOperation(value = "查询审批列表",notes = "查询审批列表")
    //@RequiresPermissions("reportApproval:productinfo:list")
    public R checklist(@RequestBody Param param){
        PageUtils page = productInfoService.queryPageCheckList(param);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping(value = "/info/{id}",method = RequestMethod.POST)
    @ApiOperation(value = "推广鉴定信息表信息",notes = "推广鉴定信息表信息")
    //@RequiresPermissions("reportApproval:productinfo:info")
    public R info(@PathVariable("id") Integer id){
		ProductInfoVos productInfoVo = productInfoService.getByIdProductInfoVo(id);

        return R.ok().put("productInfo", productInfoVo);
    }

    /**
     * 保存
     */
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    @ApiOperation(value = "推广鉴定信息表保存",notes = "推广鉴定信息表保存",produces = "application/json")
    //@RequiresPermissions("reportApproval:productinfo:save")
    public R save(@RequestBody ProductInfoVo productInfoVo){
		R r = productInfoService.saveProductInfo(productInfoVo);

        return r;
    }

    @RequestMapping(value = "/export/{id}",method = RequestMethod.POST)
    @ApiOperation(value = "检验报告信息",notes = "检验报告信息")
    //@RequiresPermissions("reportApproval:report:info")
    public R export(@PathVariable("id") Integer id){
        ProductInfoExportVoVo productInfoExportVoVo = productInfoService.getByIdproductInfoExportVo(id);

        return R.ok().put("report", productInfoExportVoVo);
    }
    @ApiOperation(value = "修改项目审批意见",notes = "修改项目审批意见", produces = "application/json")
    @PostMapping("/updateApprovalOpinion")
    //@RequiresPermissions("foundation:blapplyprojectinfo:update")
    public R updateApprovalOpinion(@RequestBody ProductInfoUpdateCheckVo productInfoUpdateCheckVo){
        return productInfoService.updateApprovalOpinion(productInfoUpdateCheckVo);
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ApiOperation(value = "推广鉴定信息表修改",notes = "推广鉴定信息表修改")
    //@RequiresPermissions("reportApproval:productinfo:update")
    public R update(@RequestBody ProductInfoVo productInfoVo){
		productInfoService.updateByIdProductInfoVo(productInfoVo);

        return R.ok();
    }

    @RequestMapping(value = "/review",method = RequestMethod.POST)
    @ApiOperation(value = "推广鉴定信息表审核",notes = "推广鉴定信息表审核")
    //@RequiresPermissions("reportApproval:productinfo:update")
    public R review(@RequestBody ProductInfoVo productInfoVo){
        productInfoService.updateById(new ProductInfo().setId(productInfoVo.getId()).setReprotStatus(String.valueOf(StateEnum.APPROVAL.getState())));
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @ApiOperation(value = "推广鉴定信息表删除",notes = "推广鉴定信息表删除")
    //@RequiresPermissions("reportApproval:productinfo:delete")
    public R delete(@RequestBody Integer[] ids){
		productInfoService.removeByIdsProductInfoVo(Arrays.asList(ids));

        return R.ok();
    }

    @ApiOperation("文件下载")
    @GetMapping("/fileUplod")
    public R fileDownload(String id) throws IOException, TemplateException, ParseException, IllegalAccessException {
        String path = productInfoService.fileDownload(id);
        return R.ok().put("path",path);
    }

    @ApiOperation("文件上传")
    @PostMapping("/fileUplod")
    public R fileUplod(String id, @RequestPart MultipartFile file) throws IOException {
        R r = productInfoService.fileUplod(id,file);
        return r;
    }

    @ApiOperation("查询文件路径")
    @GetMapping("/getProductFilePath/{id}")
    public R getProductFilePath(@PathVariable("id") String id) throws IOException, ParseException, IllegalAccessException {
        String path = productInfoService.getProductFilePath(id);
        return R.ok().put("path",path);
    }

    @ApiOperation("查询文件路径")
    @GetMapping("/getProductFileWordPath/{id}")
    public R getProductFileWordPath(@PathVariable("id") String id) throws IOException, ParseException, IllegalAccessException {
        String path = productInfoService.getProductFileWordPath(id);
        return R.ok().put("path",path);
    }

}
